package map;

import java.util.LinkedHashMap;

/**
 * LinkedHashMap是hashmap的子类，键值按照插入排序
 */
public class LinkedHashMapTest {

	public static void main(String[] args) {
		
		final int size = 2;
		LinkedHashMap<Integer, Integer> lru = new LinkedHashMap<Integer, Integer>(2, .5f, true){
			private static final long serialVersionUID = -7591783586891572644L;

			@Override
			protected boolean removeEldestEntry(java.util.Map.Entry<Integer, Integer> eldest) {
				System.out.println("删除：" + eldest);
				return size() > size;
			}
		};
		lru.put(1, 1);
		lru.put(2, 2);
		System.out.println("访问：" + lru.get(1));
		lru.put(3, 3);
		System.out.println(lru);
	}
}
